import time
from telnetlib import EC

from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait


def __init__(self):
    """
    self.user_name:b站登录账号
    self.password:b站登录密码
    self.chaojiying_user_name:超级鹰登录账号
    self.chaojiying_password:超级鹰登陆密码
    self.chaojiying_ID:超级鹰软件ID
    self.chaojiying_kind:超级鹰验证码类型
    :return:None
    """
    self.url = 'https://passport.bilibili.com/login'
    self.driver = webdriver.Chrome()
    self.driver.maximize_window()
    print(f"Driver type: {type(self.driver)}")  # 添加这行调试信息
    self.username = 'LY酱'
    self.password = 'XLPjz963852'
    self.chaojiying_user_name = '823539720'
    self.chaojiying_password = 'xlpluffy'
    self.chaojiying_ID = 'ce1eb0597d64356af98380172bcd2a4f'
    self.pic_id = ''
    self.chaojiying = chaojiying.Chaojiying_Client(self.chaojiying_user_name, self.chaojiying_password,
                                                   self.chaojiying_ID)
driver = webdriver.Chrome()
# 2访问B站
driver.get('https://bilibili.com/')
time.sleep(3)
# 3选择登录按钮 css选择器
login_button = driver.find_element(By.CSS_SELECTOR, '.bili-header .header-login-entry')
login_button.click()
time.sleep(3)

# # 4账号密码输入
# # 使用 placeholder 属性定位输入框，注意添加等待时间
# username_input = WebDriverWait(driver, 10).until(
#     EC.presence_of_element_located((By.CSS_SELECTOR, 'input[placeholder="请输入账号"]'))
# )
# password_input = WebDriverWait(driver, 10).until(
#     EC.presence_of_element_located((By.CSS_SELECTOR, 'input[placeholder="请输入密码"]'))
# )
# # 输入用户名和密码
# username_input.send_keys(username)
# password_input.send_keys(password)
# print("输入账户密码完成")
result = "267,295|205,131|168,257|265,219"
for index in result.split('|'):
    x = index.split(',')[0]
    y = index.split(',')[1]
    print(index)
    # 在点击之前尝试调整元素的位置
    # move_to_element_with_offset 在验证码上面进行点击操作
    ActionChains(driver).move_to_element_with_offset(img_label, int(x), int(y)).click().perform()
    print('执行成功')